<template>
  <div>
    <el-dialog
      title="编辑会员"
      :visible.sync="dialogInfo.isShow"
      :before-close="dialogInfo.cancel"
      center
    >
      <el-form ref="member" :model="memberinfo" :rules="rules">
        <el-form-item prop="phone" label="手机号" :label-width="formLabelWidth">
          <el-input v-model="memberinfo.phone" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item
          prop="nickname"
          label="昵称"
          :label-width="formLabelWidth"
        >
          <el-input v-model="memberinfo.nickname" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item
          prop="password"
          label="密码"
          :label-width="formLabelWidth"
        >
          <el-input v-model="memberinfo.password" autocomplete="off"></el-input>
          <span>留空则不修改</span>
        </el-form-item>

        <el-form-item label="状态" :label-width="formLabelWidth">
          <el-switch
            v-model="memberinfo.status"
            active-color="#13ce66"
            inactive-color="#ff4949"
            :active-value="1"
            :inactive-value="2"
          >
          </el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button @click="editInfo" type="primary">编辑</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapActions } from "vuex";
import {memberEdit,memberInfo} from '../../request/api'
export default {
  data() {
    return {
      memberinfo: {
        uid: 0,
        nickname: "",
        phone: "",
        password: "",
        status: 1,
      },
      rules: {
        phone: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          { min: 11, message: "长度最小11个字符", trigger: "blur" },
        ],
        nickname: [
          { required: true, message: "请输入昵称", trigger: "blur" },
          { min: 2, max: 8, message: "长度在2-8字符", trigger: "blur" },
        ],
      },
      formLabelWidth: "120px",
    };
  },
  props: ["dialogInfo"],
  mounted() {
    this.getMember();
  },
  methods: {
    ...mapActions({
      getMember: "member/getMemberActions",
    }),
    cancel() {
      this.$emit("cancel", false);
    },
    editInfo(){
              this.$refs.member.validate((val) => {
        if (val) {
          // console.log(this.menuinfo,'输出表单');
          //调用添加接口
          memberEdit(this.memberinfo).then((res) => {
            // console.log(res, "菜单添加");
            if (res.code == 200) {
              this.$message.success(res.msg);
              //添加成功关闭弹窗
              this.cancel();
              this.getMember();
            } else {
              this.$message.error(res.msg);
            }
          });
        } else {
          console.log("验证失败");
        }
      });
    },
   lookup(uid){
memberInfo({uid}).then((res) => {
        if (res.code == 200) {
          this.memberinfo = res.list;
          this.memberinfo.uid = uid;
          this.memberinfo.password = "";
        }
      });
   }
  },
};
</script>

<style scoped>
</style>
